package com.openmanus.config.persistence;

import com.openmanus.config.OpenManusProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * JPA 配置类
 * 当选择JPA作为ORM框架时启用
 * 
 * @author OpenManus Team
 * @version 1.0.0
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(name = "openmanus.persistence.orm", havingValue = "jpa", matchIfMissing = true)
@EnableJpaRepositories(basePackages = "com.openmanus.**.repository")
@EntityScan(basePackages = "com.openmanus.**.entity")
@EnableTransactionManagement
public class JpaConfiguration {

    private final OpenManusProperties properties;

    /**
     * 初始化JPA配置
     */
    public JpaConfiguration(OpenManusProperties properties) {
        this.properties = properties;
        log.info("启用JPA持久化配置: 数据库类型={}", 
                properties.getPersistence().getDatabase().getName());
    }
}
